package com.treasure.service.loan.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.treasure.service.annotation.LogInfo;
import com.treasure.service.dto.LoanDto;
import com.treasure.service.dto.TLoanOrderDto;
import com.treasure.service.enums.CodeEnum;
import com.treasure.service.loan.service.LoanService;
import com.treasure.service.result.PageResult;
import com.treasure.service.result.ResponseResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Api(value = "贷款管理",description = "贷款管理")
@RestController
@RequestMapping("/loans/v1")
@Slf4j
public class LoanController {
	@Autowired
	private LoanService loanService;
	
    @ApiOperation(value = "贷款管理", notes = "贷款管理")
    @PostMapping("/getLoanList")
    @LogInfo(log = "查询贷款列表",isPrint = true)
    public ResponseEntity updateBanner(){
    	log.info("查询贷款列表");
    	PageResult<List<LoanDto>> result = loanService.getLoanList(1,100);
    	log.info("查询贷款列表结果:"+JSON.toJSONString(result));
        return ResponseEntity.ok(result);
    }

    @ApiOperation(value = "创建贷款订单", notes = "创建贷款订单")
    @PostMapping("/createOrder")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "realName", value = "姓名", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "certNo", value = "身份证", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "mobile", value = "手机号", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "loanId", value = "贷款ID", required = true, dataType = "String", paramType = "query"),
    })
    @LogInfo(log = "创建贷款订单",isPrint = true)
    public ResponseEntity<ResponseResult> createOrder(@RequestBody TLoanOrderDto tLoanOrderDto){
    	return ResponseEntity.ok(new ResponseResult(CodeEnum.SUCCESS,loanService.createLoanOrder(tLoanOrderDto)));
    }
}
